home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / EventDispatchThread.java < prev    next >
Text File  |  1998-09-25  |  3KB  |  99 lines

  1. /*
  2.  * @(#)EventDispatchThread.java    1.18 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt;
  16.  
  17. import java.awt.event.MouseEvent;
  18. import java.awt.event.KeyEvent;
  19. import java.awt.event.PaintEvent;
  20. import java.awt.peer.ActiveEvent;
  21.  
  22. /**
  23.  * EventDispatchThread is a package-private AWT class which takes
  24.  * events off the EventQueue and dispatches them to the appropriate
  25.  * AWT components.
  26.  *
  27.  * @version 1.18 07/01/98
  28.  * @author Tom Ball
  29.  * @author Amy Fowler
  30.  */
  31. class EventDispatchThread extends Thread {
  32.     private EventQueue theQueue;
  33.     private boolean doDispatch = true;
  34.  
  35.     EventDispatchThread(String name, EventQueue queue) {
  36.     super(name);
  37.         theQueue = queue;
  38.     }
  39.  
  40.     public void stopDispatching() {
  41.         doDispatch = false;
  42.     // fix 4128923
  43.     // post an empty event to ensure getNextEvent
  44.     // is unblocked - rkhan 4/14/98
  45.     // TODO: Look into using Thread.interrupt() instead
  46.     theQueue.postEvent(new EmptyEvent());
  47.     // wait for the dispatcher to complete
  48.     if (Thread.currentThread() != this) {
  49.         try {
  50.         join();
  51.         } catch(InterruptedException e) {
  52.         }
  53.     }
  54.     }
  55.  
  56.     class EmptyEvent extends AWTEvent implements ActiveEvent {
  57.     public EmptyEvent() {
  58.         super(EventDispatchThread.this,0);
  59.     }
  60.  
  61.     public void dispatch() {}
  62.     }
  63.  
  64.     public void run() {
  65.        while (doDispatch) {
  66.             try {
  67.                 AWTEvent event = theQueue.getNextEvent();
  68.                 if (false) {
  69.                     // Not until 1.2...
  70.                     // theQueue.dispatchEvent(event);
  71.                 } else {
  72.                     // old code..
  73.                     //__SYMC__
  74.                     SymantecEventHook.Manager.beforeEvent(event);
  75.                     Object src = event.getSource();
  76.                     if (event instanceof ActiveEvent) {
  77.             // This could become the sole method of dispatching in time, and 
  78.             // moved to the event queue's dispatchEvent() method.
  79.             ((ActiveEvent)event).dispatch();
  80.             } else if (src instanceof Component) {
  81.                         ((Component)src).dispatchEvent(event);
  82.                     } else if (src instanceof MenuComponent) {
  83.                         ((MenuComponent)src).dispatchEvent(event);
  84.             }
  85.                     //__SYMC__
  86.                     SymantecEventHook.Manager.afterEvent(event);
  87.                 }
  88.             } catch (ThreadDeath death) {
  89.                 return;
  90.  
  91.             } catch (Throwable e) {
  92.                 System.err.println(
  93.                     "Exception occurred during event dispatching:");
  94.                 e.printStackTrace();
  95.             }
  96.         }
  97.     }
  98. }
  99.